package com.shop2cn.iapi.agentproducts.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ExistDepotProductBean;
import com.shop2cn.iapi.agentproducts.service.ExistDepotProductCall;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.utils.AgentUsers;
/**
*查询仓库是否有商品使用Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ExistDepotProduct{
	private static ExistDepotProductBean existdepotproductBean;
	private static ExistDepotProductCall existdepotproductCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询仓库是否有商品使用Test");
	}

	@Before
	public void caseUp() {
		existdepotproductBean=new ExistDepotProductBean();
		existdepotproductCall=new ExistDepotProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(existdepotproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistDepotProduct_001() {
		Logger.start(true,"仓库里面有商品");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			createDepotBean bean = GodmchManageCallService.createDepot(rootUserId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService
					.SelectDepotByDepotTitle(bean.getDepotTitle());
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			existdepotproductBean.setMchId(rootUserId);
			existdepotproductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			existdepotproductCall.setData(existdepotproductBean);
			existdepotproductCall.callService();	
			
			Logger.verifyEquals("200", existdepotproductCall.getString("code"), "验证code");
			Logger.verifyEquals(true, existdepotproductCall.getJsonObject().getAsJsonObject("data").get("exist").getAsBoolean(), "验证是否存在");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistDepotProduct_002() {
		Logger.start(true,"仓库里面没有商品");
		try {
			createDepotBean bean = GodmchManageCallService.createDepot(rootUserId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService
					.SelectDepotByDepotTitle(bean.getDepotTitle());
			Thread.sleep(5000);
			existdepotproductBean.setMchId(rootUserId);
			existdepotproductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			existdepotproductCall.setData(existdepotproductBean);
			existdepotproductCall.callService();	
			
			Logger.verifyEquals("200", existdepotproductCall.getString("code"), "验证code");
			Logger.verifyEquals(false, existdepotproductCall.getJsonObject().getAsJsonObject("data").get("exist").getAsBoolean(), "验证是否存在");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistDepotProduct_003() {
		Logger.start(true,"仓库id错误");
		try {
			existdepotproductBean.setMchId(rootUserId);
			existdepotproductBean.setDepotId(11223344);
			existdepotproductCall.setData(existdepotproductBean);
			existdepotproductCall.callService();	
			
			Logger.verifyEquals("200", existdepotproductCall.getString("code"), "验证code");
			Logger.verifyEquals(false, existdepotproductCall.getJsonObject().getAsJsonObject("data").get("exist").getAsBoolean(), "验证是否存在");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistDepotProduct_004() {
		Logger.start(true,"用户id错误");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			createDepotBean bean = GodmchManageCallService.createDepot(rootUserId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService
					.SelectDepotByDepotTitle(bean.getDepotTitle());
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			existdepotproductBean.setMchId(112233);
			existdepotproductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			existdepotproductCall.setData(existdepotproductBean);
			existdepotproductCall.callService();	
			
			Logger.verifyEquals("200", existdepotproductCall.getString("code"), "验证code");
			Logger.verifyEquals(false, existdepotproductCall.getJsonObject().getAsJsonObject("data").get("exist").getAsBoolean(), "验证是否存在");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}